<?php 
namespace app\index\controller;
use think\Controller;


use app\index\model\User as UserModel;




header("Content-type: text/html; charset=utf-8"); 
//验证类

//登录页面展示
class Register extends Controller{

	public function index(){

        //展示用户注册页面
		return $this->fetch();
	}

	//接受用户注册FORM

	//加入用户重名限制AJAX

	public function indexForm(){

        $RegisterInfo = input('post.');
        //dump($RegisterInfo);

		$Import_man = $RegisterInfo['import_man'] ? $RegisterInfo['import_man'] : 0;

        //给出模型
        $userModel = new UserModel();

        $userModel->data([

            'username' => $RegisterInfo['username'],
            'password' => $RegisterInfo['password'],
           	'import_man_id' => $Import_man
        ]);
        $Reslut = $userModel->save();

        //插入账户表中数据
        $Res = $userModel->Account()->save(['sell_list' => '0','username' => $RegisterInfo['username']]);



        if($Reslut && $Res){
        	//保存成功
			//echo"保存成功!!!";

            return $this->redirect("Login/index");

		}else{
        	//保存失败
			//echo "保存失败";
			$this->error("保存失败!!!");
		}
	}

	//跳转登录页面
	public function  redirectLogin(){
		$this->redirect("Login/index");
	}

	public function  verifyName(){

		$RegisterName = input('post.');
        $RegName= trim($RegisterName['element_name']);

		//file_put_contents('2.txt',$RegName,FILE_APPEND);

		$User = new UserModel();
		$Res= $User->where('username',$RegName)->find();

		if($Res){
			//名字存在
            return json_encode(1);
		}else{
			//名字不存在
            return json_encode(0);
		}
	}


}
 ?>
